/*
 * Copyright 2009 Vladimir Ritz Bossicard
 *
 * This file is part of OraDoc.
 *
 * OraDoc is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * Version     : $Revision: 23 $
 * Last edit   : $Date: 2009-05-29 11:58:29 +0000 (Fri, 29 May 2009) $
 * Last editor : $Author: vbossica $
 */
package org.oradoc;

import org.oradoc.projects.Project;
import org.oradoc.projects.outputters.ProjectOutputter;
import org.oradoc.structures.dao.TableDao;
import org.oradoc.structures.dao.ViewDao;
import org.springframework.config.java.context.JavaConfigApplicationContext;

/**
 *
 * @author Vladimir Ritz Bossicard
 */
public class Generator {

    private Project project;
    private ProcessListener listener;
    private ProjectOutputter outputter;

    public void init(final String className, final ProcessListener listener) throws Exception {
        this.listener = listener;

        Class<?> configCls = Class.forName(className);
        JavaConfigApplicationContext ctx = new JavaConfigApplicationContext(configCls);

        this.project = (Project) ctx.getBean("project");
        this.outputter = (ProjectOutputter) ctx.getBean("outputter");
        this.project.setTableDao((TableDao) ctx.getBean("tableDao"));
        this.project.setViewDao((ViewDao) ctx.getBean("viewDao"));
    }

    public void process() throws Exception {
        this.listener.start();
        this.project.process(this.listener);

        this.listener.info("generating files");
        this.outputter.output(this.project);
        this.listener.finished();
    }

    public void setProperty(final String key, final String value) {
        System.setProperty(key, value);
    }

}
